<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-10-04
 * Time: 11:57
 */
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\Smscode as cxModel;
use app\common\model\UserData;

class Smscode extends Apibase{
    /**
     * 本方法仅接收POST数据
     * phone 手机号码
     * @return \think\response\Json
     */
    public function postSmscode(){
        $getlist['code'] = '0';
        if(!request()->isPost()){
            $getlist['msg'] = '访问错误！';
            return json($getlist);
        }
        $getdata = input();
        $getdata = datatrim($getdata);
        $cxmodel = new cxModel();
        $usermodel = new UserData();
        switch ($getdata['type']){
            case '1':
                $phone = $usermodel->where('uphone',$getdata['phones'])->count();
                if($phone == '0'){
                    $getlist['msg'] = '手机不存在！';
                    return json($getlist);
                }
                $getdata['tpcode'] = $this->webdb['aliyuncode'];
                break;
            case '1001':
                $phone = $usermodel->where('uphone',$getdata['phones'])->count();
                if($phone > 0){
                    $getlist['msg'] = '手机已存在！';
                    return json($getlist);
                }
                $getdata['tpcode'] = $this->webdb['aliyuncode'];
                break;
        }

        $getdata = $cxmodel->smscode($getdata);
        $getlist['code'] = $getdata['status'];
        $getlist['cont'] = $getdata;
        if($getlist['code'] == '1'){
            $getlist['msg'] = '发送成功';
        }
        if($getlist['code'] == '0'){
            $getlist['msg'] = '发送失败';
        }
        return json($getlist);
    }




}